package cn.gok.util;

import java.sql.*;


public class JDBCUtils {
    public static void main(String[] args) throws SQLException {
        String username="root";
        String password="root";
        String url="jdbc:mysql://localhost:3306/my";
        String sql="select * from user where id=?";


        Connection con= null;
        Statement statement =null;
        PreparedStatement ps =null;
        ResultSet rs =null;
        try{
            Class.forName("com.mysql.jdbc.Driver");
            con= DriverManager.getConnection(url,username,password);
            statement =con.prepareStatement(sql);
            ps =con.prepareStatement(sql);
            rs =ps.executeQuery(sql);
        while(rs.next()){
            System.out.println(rs.getInt(1)+rs.getString(2)+rs.getInt(3));
        }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            rs.close();
            ps.close();
            con.close();
        }
    }
}
